package com.dragon.client.controller.auth;

import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.auth.IDictsortService;
import com.dragon.repository.domain.dto.DictsortDTO;
import com.dragon.repository.domain.vo.DictsortVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典分类 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-06-27
 */
@RestController
@RequestMapping("dictsort")
@Api(tags = "字典分类")
public class DictsortController {

    @Autowired
    IDictsortService service;


    @GetMapping("list")
    @ApiOperation(value = "字典分类列表")
    public ResponseData<List<DictsortDTO>> selectList(){
        return ResponseData.success(DictsortDTO.convertList(service.selectAllList()));
    }


    @PostMapping("add")
    @ApiOperation(value = "添加")
    public ResponseData addDictsort(@RequestBody @Validated(Insert.class) DictsortVO vo){
        return ResponseData.success(service.addDictsort(DictsortVO.convert(vo)));
    }


    @PostMapping("update")
    @ApiOperation(value = "修改")
    public ResponseData updateDictsort(@RequestBody @Validated(Update.class) DictsortVO vo){
        service.updateDictsort(DictsortVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除")
    public ResponseData deleteDictsort(@RequestParam @ApiParam(name = "id",required = true,value = "id",type = "int") Integer id){
        service.deleteDictsort(id);
        return ResponseData.success();
    }

}
